@echo off
chcp 65001
setlocal enabledelayedexpansion

REM 参数1：APK完整路径
set "apk_path=%~1"
if not exist "%apk_path%" (
    echo 输入文件不存在：%apk_path%
    exit /b 1
)

REM 当前时间戳 yyyyMMddHHmm
for /f "tokens=1-4 delims=/.- " %%a in ("%date%") do (
    set yyyy=%%d
    set mm=%%b
    set dd=%%c
)
for /f "tokens=1-2 delims=:." %%i in ("%time%") do (
    set hh=%%i
    set min=%%j
)

if 1!hh! LSS 110 set hh=0!hh!
if 1!min! LSS 110 set min=0!min!
set "timestamp=!yyyy!!mm!!dd!!hh!!min!"

REM 获取路径和文件名
for %%F in ("%apk_path%") do (
    set "apk_dir=%%~dpF"
    set "apk_file=%%~nxF"
    set "apk_ext=%%~xF"
)

REM 直接截取前缀（去掉最后17位：包括“_202505272204”和“.apk”）
set "base_name=!apk_file:~0,-17!"

set "new_name=!base_name!_!timestamp!!apk_ext!"
set "new_path=!apk_dir!!new_name!"

ren "%apk_path%" "!new_name!"

echo !new_path!
endlocal & set "renamed_apk_path=%new_path%"
exit /b 0
